<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:mv="http://java.sun.com/jsf/composite/component">

<ui:composition template="../template/layout.xhtml">

	<ui:define name="content">
		
		<div align="left">
			<h1>#{bundle.label_title_list_customer}</h1>		
		</div>
		
		<div align="right">
			<p:commandButton value="#{bundle.label_new}" update=":form" actionListener="#{customerMB.openModal}" oncomplete="dialogForm.show();"/>
		</div>
	
		<p:spacer height="10"/>

		<h:form id="formList" prependId="false">	
			<p:dataTable value="#{customerMB.customerList}" var="customer" id="list">
				<p:column headerText="#{bundle.label_code}">
					<h:outputText value="#{customer.id}" />
				</p:column>
				<p:column headerText="#{bundle.label_name_corporate_name}">
					<h:outputText value="#{customer.entity.corporateName}" rendered="#{customer.entity.entityType.id == 1}"/>
					<h:outputText value="#{customer.entity.name}" rendered="#{customer.entity.entityType.id == 1}"/>
				</p:column>
				<p:column headerText="#{bundle.label_cpf_cnpj}">
					<h:outputText value="#{customer.entity.cnpj}" rendered="#{customer.entity.entityType.id == 1}"/>
					<h:outputText value="#{customer.entity.cpf}" rendered="#{customer.entity.entityType.id == 2}"/>
				</p:column>
				<p:column headerText="#{bundle.label_city}">
					<h:outputText value="#{customer.entity.address.city.name}" />
				</p:column>
				<p:column style="width : 130px;">
					<p:commandLink value="#{bundle.label_edit}" update=":form" action="#{customerMB.entitySelected}" oncomplete="dialogForm.show();" title="#{bundle.label_edit}">
						<f:setPropertyActionListener value="#{customer}" target="#{customerMB.customer}" />
					</p:commandLink>
					<p:spacer width="5"/>
					<p:commandLink value="#{bundle.label_remove}" action="#{customerMB.entitySelected}" process="@this" oncomplete="confirmation.show();" title="#{bundle.label_remove}">
						<f:setPropertyActionListener value="#{customer}" target="#{customerMB.customer}" />
					</p:commandLink>
				</p:column>	
			</p:dataTable>
			<mv:paginator update="@form" paginator="#{customerMB.paginator}"></mv:paginator>
			<mv:dialogRemove update="@form" managedBean="#{customerMB}"></mv:dialogRemove>
		</h:form>
		
		<h:form id="form" prependId="false">  
			
			<p:dialog id="dialogForm" header="#{bundle.label_title_form_customer}" widgetVar="dialogForm" modal="true" height="500" width="600" resizable="false">
	        		
	        	<p:outputPanel id="panelForm">
	        		<table>
	        			<tr>
	        				<td>
	        					<h:outputLabel for="entityType" value="#{bundle.label_entity_type}:" rendered="#{customerMB.customer.id == -1}">
				        			<br/>
									<p:selectOneMenu id="entityType" value="#{customerMB.customer.entity.entityType}" converter="entityConverter"
													 style="width:150px;" rendered="#{customerMB.customer.id == -1}">
										<f:selectItems value="#{customerMB.entityTypeList}"/>	
										<p:ajax event="change" update="panelForm"/>						
									</p:selectOneMenu>
								</h:outputLabel>
	        				</td>
	        			</tr>
	        			<tr>
	        				<td>
	        					<h:outputLabel value="#{bundle.label_name}:" for="name" rendered="#{customerMB.customer.entity.entityType.id == 2}">
				        			<br />
				        			<p:inputText value="#{customerMB.customer.entity.name}" id="name" styleClass="inputDefault" rendered="#{customerMB.customer.entity.entityType.id == 2}"/>
				        		</h:outputLabel>
	        				</td>
	        				<td>
	        					<h:outputLabel value="#{bundle.label_cpf}:" for="cpf" rendered="#{customerMB.customer.entity.entityType.id == 2}">
				        			<br />
				        			<p:inputMask mask="999.999.999-99" value="#{customerMB.customer.entity.cpf}" id="cpf" styleClass="inputDefault" rendered="#{customerMB.customer.entity.entityType.id == 2}"/>
				        		</h:outputLabel>
	        				</td>
	        			</tr>
	        			<tr>
	        				<td>
		        				<h:outputLabel value="#{bundle.label_corporate_name}:" for="corporateName" rendered="#{customerMB.customer.entity.entityType.id == 1}">
				        			<br />
				        			<p:inputText value="#{customerMB.customer.entity.corporateName}" id="corporateName" styleClass="inputDefault" rendered="#{customerMB.customer.entity.entityType.id == 1}"/>
				        		</h:outputLabel>	
				        	</td>
	        				<td>	
				        		<h:outputLabel value="#{bundle.label_fantasy_name}:" for="fantasyName" rendered="#{customerMB.customer.entity.entityType.id == 1}">
				        			<br />
				        			<p:inputText value="#{customerMB.customer.entity.fantasyName}" id="fantasyName" styleClass="inputDefault" rendered="#{customerMB.customer.entity.entityType.id == 1}"/>
				        		</h:outputLabel>
	        				</td>
	        			</tr>
	        			<tr>
	        				<td>
		        				<h:outputLabel value="#{bundle.label_cnpj}:" for="cnpj" rendered="#{customerMB.customer.entity.entityType.id == 1}">
				        			<br />
				        			<p:inputMask mask="99.999.999/9999-99" value="#{customerMB.customer.entity.cnpj}" id="cnpj" styleClass="inputDefault" rendered="#{customerMB.customer.entity.entityType.id == 1}"/>
				        		</h:outputLabel>
				        	</td>
	        				<td>	
				        		<h:outputLabel value="#{bundle.label_responsible}:" for="responsible" rendered="#{customerMB.customer.entity.entityType.id == 1}">
				        			<br />
				        			<p:inputText value="#{customerMB.customer.entity.responsible}" id="responsible" styleClass="inputDefault" rendered="#{customerMB.customer.entity.entityType.id == 1}"/>
				        		</h:outputLabel>
	        				</td>
	        			</tr>
	        			<tr>
	        				<td>
		        				<h:outputLabel value="#{bundle.label_fone_primary}:" for="fonePrimary">
				        			<br />
				        			<p:inputMask mask="(99)9999-9999" value="#{customerMB.customer.entity.contact.fonePrimary}" id="fonePrimary" styleClass="inputDefault"/>
				        		</h:outputLabel>
				        	</td>
	        				<td>	
				        		<h:outputLabel value="#{bundle.label_fone_secondary}:" for="foneSecondary">
				        			<br />
				        			<p:inputMask mask="(99)9999-9999" value="#{customerMB.customer.entity.contact.foneSecondary}" id="foneSecondary" styleClass="inputDefault"/>
				        		</h:outputLabel>
	        				</td>
	        			</tr>
	        			<tr>
	        				<td colspan="2">
	        					<h:outputLabel value="#{bundle.label_email}:" for="email">
				        			<br />
				        			<p:inputText value="#{customerMB.customer.entity.contact.email}" id="email" styleClass="inputBig"/>
				        		</h:outputLabel>
	        				</td>
	        			</tr>
	        			<tr>
	        				<td colspan="2">
		        				<h:outputLabel value="#{bundle.label_street}:" for="street">
				        			<br />
				        			<p:inputText value="#{customerMB.customer.entity.address.street}" id="street" styleClass="inputBig"/>
				        		</h:outputLabel>
				        	</td>
	        			</tr>
	        			<tr>
	        				<td>
		        				<h:outputLabel value="#{bundle.label_district}:" for="district">
				        			<br />
				        			<p:inputText value="#{customerMB.customer.entity.address.district}" id="district" styleClass="inputDefault"/>
				        		</h:outputLabel>
				        	</td>
	        				<td>	
				        		<h:outputLabel value="#{bundle.label_cep}:" for="cep">
				        			<br />
				        			<p:inputText value="#{customerMB.customer.entity.address.cep}" id="cep" styleClass="inputDefault"/>
				        		</h:outputLabel>
	        				</td>
	        			</tr>
	        			<tr>
	        				<td>	
				        		<h:outputLabel value="#{bundle.label_federal_unit}:" for="federalUnit">
				        			<br />
									<p:selectOneMenu id="federalUnit" value="#{customerMB.customer.entity.address.city.federalUnit}" 
													 converter="entityConverter" style="width : 260px;">
										<f:selectItems value="#{customerMB.federalUnitList}"/>	
									</p:selectOneMenu>
				        		</h:outputLabel>
	        				</td>
	        				<td>
		        				<h:outputLabel value="#{bundle.label_city}:" for="city">
				        			<br />
				        			<p:inputText value="#{customerMB.customer.entity.address.city.name}" id="city" styleClass="inputDefault"/>
				        		</h:outputLabel>
				        	</td>
	        			</tr>
	        			<tr>
	        				<td colspan="2">
		        				<h:outputLabel value="#{bundle.label_observation}:" for="observationAddress">
				        			<br />
				        			<p:inputTextarea value="#{customerMB.customer.entity.address.observation}" id="observationAddress" styleClass="inputDefault"/>
				        		</h:outputLabel>
				        	</td>
	        			</tr>
	        		</table>
	        	</p:outputPanel>		
	        	
	        	<div align="right">
	        		<p:commandButton value="#{bundle.label_save}" actionListener="#{customerMB.save}" update=":form, :formList" oncomplete="#{customerMB.oncomplete}"/>
	        		<p:commandButton value="#{bundle.label_cancel}" onclick="dialogForm.hide();"/>	
	        	</div>
	        		 	 
			</p:dialog>
        </h:form>	
		
	</ui:define>
</ui:composition>
</html>